﻿using System;
using System.Linq.Expressions;
using System.Text.RegularExpressions;
using Fuse8.DomainFramework.Domain;

namespace Fuse8.DomainFramework.DataAccess.SqlDatabase.Formatters
{
	internal class NotEqualsFormattingService : IFormattingService
	{
		public object FormatObject(object obj, ExpressionType? parentExpressionType)
		{
			var result = obj;
			if (result is string)
			{
				result = Regex.Replace((string)result, @"!=\s*[(]?\s*NULL\s*[)]?", "IS NOT NULL");
			}
			return result;
		}

		public Expression CreateFormatDelegate(Expression expression, ExpressionType? parentExpressionType)
		{
			return expression;
		}
	}
}